//
//  NRWHomeChannelView.m
//  NRWMall
//
//  Created by 邢毅 on 2018/5/22.
//  Copyright © 2018年 com.anpxd. All rights reserved.
//

#import "NRWHomeChannelView.h"

@interface NRWHomeChannelView()

@property (strong, nonatomic) UIButton *certifyBtn;

@property (strong, nonatomic) UIButton *subscribeBtn;

@property (strong, nonatomic) UIButton *carsBtn;

@property (strong, nonatomic) UIView *lineView;

@property (strong, nonatomic) UIButton *lastClickBtn;

@end

@implementation NRWHomeChannelView

- (instancetype)init
{
    self = [super init];
    if (self) {
    
        self.certifyBtn = DPButton()
        .setNormalTitle(@"启辕认证")
        .setNormalTitleColor(getColor(@"#666666"))
        .setSelectedTitleColor(getColor(@"#FF6C00"))
        .setTitleFont(getThemeFont(13))
        .setTag(0)
        .addClickAction(self, @selector(btnDidClick:));
//        self.lastClickBtn = self.certifyBtn;
//        self.lastClickBtn.selected = YES;
        
        self.subscribeBtn = DPButton()
        .setNormalTitle(@"订阅车源")
        .setNormalTitleColor(getColor(@"#666666"))
        .setSelectedTitleColor(getColor(@"#FF6C00"))
        .setTag(1)
        .setTitleFont(getThemeFont(13))
        .addClickAction(self, @selector(btnDidClick:));
        
        self.carsBtn = DPButton()
        .setNormalTitle(@"最新车源")
        .setNormalTitleColor(getColor(@"#666666"))
        .setSelectedTitleColor(getColor(@"#FF6C00"))
        .setTag(2)
        .setTitleFont(getThemeFont(13))
        .addClickAction(self, @selector(btnDidClick:));
        self.self.lastClickBtn = self.carsBtn;
        self.carsBtn.selected = YES;
        
        self.addSubview(self.certifyBtn).addSubview(self.subscribeBtn).addSubview(self.carsBtn);
        
        [self.carsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.bottom.equalTo(self);
            make.right.equalTo(self.mas_centerX);
        }];
        
        [self.certifyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_centerX);
            make.top.bottom.right.equalTo(self);
        }];
        
//        [@[self.certifyBtn, self.subscribeBtn, self.carsBtn] mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:80 leadSpacing:getAdaptationWidth(40) tailSpacing:getAdaptationWidth(40)];
//
//        [@[self.certifyBtn, self.subscribeBtn, self.carsBtn] mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.bottom.equalTo(self);
//        }];
        
        self.lineView = DPView().setBackgroundColor(getColor(@"#FF6C00"));
        self.addSubview(_lineView);
        
    }
    return self;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    self.lineView.frame = CGRectMake(0, self.viewHeight - 1, 80, 1);
    self.lineView.setCenterX(self.lastClickBtn.centerX);
}

- (void)btnDidClick:(UIButton *)sender {
    
    self.lastClickBtn.selected = NO;
    sender.selected = YES;
    self.lastClickBtn = sender;
    
    self.lineView.setCenterX(sender.centerX);
    
    if ([self.delegate respondsToSelector:@selector(homeChannelView:didSelectedWithIndex:)]) {
        
        [self.delegate homeChannelView:self didSelectedWithIndex:sender.tag];
    }
}

@end
